package com.itxiao.controller;

import com.itxiao.config.SystemConfig;
import com.itxiao.entity.SysMenu;
import com.itxiao.pojo.vo.PageResult;
import com.itxiao.pojo.vo.R;
import com.itxiao.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * (SysMenu)表控制层
 *
 * @author makejava
 * @since 2025-09-17 14:33:12
 */
@RestController
@RequestMapping("admin/api/v1/sys-menu")
@Api(tags = "系统菜单模块")
@CrossOrigin
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;
    @ApiOperation("分页查询")
    @PostMapping("/query")
    public R queryList() {
        PageResult<SysMenu> result = new PageResult<>(sysMenuService.list(),sysMenuService.list().size());
        return R.ok(result);
    }
    @ApiOperation("添")
    @PostMapping("/add")
    public R add(@RequestBody SysMenu sysMenu) {
        return R.ok(sysMenuService.save(sysMenu));
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public R update(@RequestBody SysMenu sysMenu) {
        return R.ok(sysMenuService.updateById(sysMenu));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/delete")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        return R.ok(sysMenuService.removeBatchByIds(ids));
    }

    @ApiOperation("单个删除")
    @DeleteMapping("/delete/{id}")
    public R deleteById(@PathVariable Integer id) {
        return R.ok(sysMenuService.removeById(id));
    }
    @ApiOperation("查询树状菜单")
    @GetMapping("/tree-select")
    public R queryTreeList() {
       return sysMenuService.queryTreeList();
    }
    @ApiOperation("查询角色所属菜单")
    @GetMapping("/role-belong-menu/{id}")
    public R queryRoleBelongMenu(@PathVariable Integer id) {
       return sysMenuService.queryRoleBelongMenu(id);
    }
    @ApiOperation("得到登录用户菜单")
    @GetMapping("/get-routers")
    public R getRouters(HttpServletRequest request) {
        return sysMenuService.getRouters(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}

